﻿using System;
using FlashCards.SL.FlashCardRepeater.Utils.Interfaces;
using FlashCards.SL.FlashCardRepeater.ViewModels;
using System.Collections.Generic;

namespace FlashCards.SL.FlashCardRepeater.Utils
{
    public class RandomFlashcardSelector : IFlashcardsSelector
    {

        private List<FlashcardViewModel> _flashcards;
        private List<FlashcardViewModel> _leftFlashcards;
        private Random _rand;

        public RandomFlashcardSelector(List<FlashcardViewModel> flashcards)
        {
            _flashcards = flashcards;
            _leftFlashcards = new List<FlashcardViewModel>();
            _leftFlashcards.AddRange(_flashcards);
            _rand = new Random();
        }

        public FlashcardViewModel GetNext()
        {
            FlashcardViewModel flashcard = null;
            if (_leftFlashcards.Count != 0)
            {
                var index = _rand.Next(0, _leftFlashcards.Count - 1);
                flashcard = _leftFlashcards[index];
                _leftFlashcards.RemoveAt(index);
            }

            return flashcard;
        }


        public int GetFlashcardsUntilEnd()
        {
            return _leftFlashcards.Count;
        }
    }
}
